package com.cnhis.cloudhealth.clinical.clidoctor.advicevaluation.bo;

import java.util.*;

import javax.annotation.Resource;

import com.cnhis.cloudhealth.commons.util.DateUtil;
import org.apache.commons.collections.MapUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.cnhis.cloudhealth.clinical.clidoctor.advicevaluation.dao.AdviceValuationDao;
import com.cnhis.cloudhealth.clinical.clidoctor.clinewadvice.bo.CliNewAdviceBo;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.utils.DateUtils;
import com.cnhis.cloudhealth.commons.utils.StaticKeys;

@Service
public class AdviceValuationBo
{
    @Resource
    private AdviceValuationDao adviceValuationDao;
    Logger log = Logger.getLogger(AdviceValuationBo.class);
    
    public ModelVo unSendAdviceValuation(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = adviceValuationDao.unSendAdviceValuation(map);
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
    
    public ModelVo sendedAdviceValuation(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = adviceValuationDao.sendedAdviceValuation(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
    
    public ModelVo getChargeInfo(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = adviceValuationDao.getChargeInfo(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
    
    public ModelVo findFeeItem(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = adviceValuationDao.findFeeItem(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
    
    public ModelVo findDrugSpecification(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = adviceValuationDao.findDrugSpecification(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo otherAdviceCharg(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        Object lDate = map.get("aDate");
        try
        {
            if (lDate == null || "".equals(lDate.toString()))
            {
                map.put("aDate", DateUtils.getDateStr(new Date()) + " 23:59:59");
            }
            else
            {
                map.put("aDate", lDate + " 23:59:59");
            }
            list = adviceValuationDao.otherAdviceCharg(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
    
    public ModelVo sendOtheradvice(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            if (!"1".equals(map.get("acf01").toString()))
            {
                mo.setResult(StaticKeys.OH_FALSE);
                mo.setResultMsg("参数不正确");
                return mo;
            }
            list = adviceValuationDao.sendOtheradvice(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
    
    public ModelVo sendTempAdviceValuation(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        String date1 = MapUtils.getString(map,"date1");
        String date2 = MapUtils.getString(map,"date2");
        int range = DateUtil.timeRange(date1,date2);
        List list = new ArrayList();
        try
        {
            if (!"1".equals(map.get("acf01").toString()))
            {
                mo.setResult(StaticKeys.OH_FALSE);
                mo.setResultMsg("参数不正确");
                return mo;
            }
            if(range==0){
                list = adviceValuationDao.sendTempAdviceValuation(map);
            }else{
                list = adviceValuationDao.sendTempAdviceValuation1(map);
            }

            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
    
    public ModelVo sendedAdviceCaoyaoValuation(HashMap map)
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = adviceValuationDao.sendedAdviceCaoyaoValuation(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
    
    public ModelVo unSendAdviceXiyaoValuation(HashMap map)
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = adviceValuationDao.unSendAdviceXiyaoValuation(map);
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
    
    public ModelVo unSendAdviceZhongyaoValuation(HashMap map)
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = adviceValuationDao.unSendAdviceZhongyaoValuation(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
    
    public ModelVo queryForSendParams(HashMap map)
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            long l1 = System.currentTimeMillis();
            log.info("----------------------------------------------准备计价数据开始:------------------------------------------------------");
            list = adviceValuationDao.queryForSendParams(map);
            mo.setList(list);
            mo.setResult(StaticKeys.OH_SUCCESS);
            long l2 = System.currentTimeMillis();
            log.info("----------------------------------------------计价数准备据耗时:"+((l2-l1))+"毫秒------------------------------------------------------");
            return mo;
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
    }

    public ModelVo unsendadvicevaluationCailiao(HashMap map)
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = adviceValuationDao.unsendadvicevaluationCailiao(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
}
